// import { saveAs } from 'file-saver';
import packages from "../../../package.json";

class AlgorithmBase{
  constructor(id='AlgorithmBase')
  {
    this.id          = id;
    this.name        = '';
    this.description = '';
    // 图/表，训练和测试DOM对象
    let domElementList = {};
    domElementList.description  = document.getElementById('description');
    domElementList.collect      = document.getElementById('collect');
    domElementList.prepare      = document.getElementById('prepare');
    domElementList.analysis     = document.getElementById('analysis');
    domElementList.train        = document.getElementById('train');
    domElementList.test         = document.getElementById('test');
    domElementList.usage        = document.getElementById('usage');

    this.domElementList = domElementList;
    this.homepage       = packages.homepage;
  }
  // 重置所有数据集和UI
  reset(){
    this.dataset = undefined;
    this.trainDS = undefined;
    this.testDS  = undefined;
    this.clear();
  }
  // 初始化训练集和测试集，和模型，必要时给定初值
  init(){ 
    console.log(this.id);
    this.clear();
  }
  initTest(){}

  initUIs(){
    this.initDescriptionUI();
    this.initCollectUI();
    this.initPrepareUI();
    this.initAnalysisUI();
    this.initTrainUI();
    this.initTestUI();
    this.initUsageUI();
  }
  initDescriptionUI(){
    const descritionDiv = document.createElement('div');
    this.domElementList.description.appendChild(descritionDiv);
    this.descritionDiv  = descritionDiv;
  }
  initCollectUI(){
    const collectDiv = document.createElement('div');
    this.domElementList.collect.appendChild(collectDiv);
    this.collectDiv  = collectDiv;
  }
  initPrepareUI(){
    const prepareDiv = document.createElement('div');
    this.domElementList.prepare.appendChild(prepareDiv);
    this.prepareDiv  = prepareDiv;
  }
  initAnalysisUI(){
    const analysisDiv = document.createElement('div');
    this.domElementList.analysis.appendChild(analysisDiv);
    this.analysisDiv  = analysisDiv;
  }
  initTrainUI(){
    const trainDiv = document.createElement('div');
    this.domElementList.train.appendChild(trainDiv);
    this.trainDiv  = trainDiv;
  }
  initTestUI(){
    const testDiv = document.createElement('div');
    this.domElementList.test.appendChild(testDiv);
    this.testDiv  = testDiv;
  }
  initUsageUI(){
    const usageDiv = document.createElement('div');
    this.domElementList.usage.appendChild(usageDiv);
    this.usageDiv  = usageDiv;
  }
  // 清除DOM数据
  clear(){
    for (let key in this.domElementList) {
      if(this.domElementList[key]){
        this.domElementList[key].innerText = '';
      }
    }

    this.initUIs();
  }
  // 导入收集数据
  load(){return false;}
  // 载入文本数据
  loadTrainDS(url, args){
    this.collect(url);
  }
  loadTestDS(){}
  // 收集数据
  collect(){};
  // 准备数据
  prepare(){return false;}
  // 分析数据
  analysis(){return false;}
  // 训练算法
  train(){return false;}
  // 测试算法
  test(){return false;}
}

export default AlgorithmBase;